#include "../../framework/framework.h"
#include "../inc/xSas.h"
namespace Sky
{

	TBool xSas::attach( xEffect* effect )
	{
		xAssertA(effect && effect->getEffect());
		D3DXEFFECT_DESC desc;
		D3DXTECHNIQUE_DESC tech_desc;
		D3DXPASS_DESC pass_desc;
		LPD3DXEFFECT pEffect = effect->getEffect();

		
		D3DXHANDLE hTecheque;
		D3DXHANDLE hPass;
		D3DXHANDLE hAnnotation;
		const TAchar* strValue;
		myDxV_Ret_M(pEffect->GetDesc(&desc));
		for(TInt i = 0 ; i < desc.Techniques ; i ++)
		{
			hTecheque = pEffect->GetTechnique(i);
			if(hTecheque == vNull)continue;
			if(XE_OK == pEffect->GetTechniqueDesc(hTecheque,&tech_desc))
			{
				xInfor1A("%s",tech_desc.Name);
				for(TInt j = 0; j < tech_desc.Passes; j ++)
				{
					hPass = pEffect->GetPass(hTecheque,j);
					if(hPass == vNull)continue;
					if(XE_OK == pEffect->GetPassDesc(hPass,&pass_desc))
					{
						xInfor1A("%s",pass_desc.Name);
						for(TInt k = 0; k < tech_desc.Passes ; k ++)
						{
							hAnnotation = pEffect->GetAnnotation(hPass,k);
							if(hAnnotation == vNull)continue;
							if(XE_OK == pEffect->GetString(hAnnotation,&strValue))
							{
								xInfor1A("%s",strValue);
							}
						}
					}
				}
			}
			
		} // for(TInt i = 0 ; i < desc.Techniques ; i ++)
		D3DXHANDLE hParameter;
		D3DXPARAMETER_DESC para_desc;
		pEffect->GetParameterDesc(vNull,&para_desc);
		for(TInt i = 0 ; i < desc.Parameters; i ++)
		{
			hParameter = pEffect->GetParameter(vNull,i);
			if(hParameter == vNull)continue;
			if(XE_OK == pEffect->GetParameterDesc(hParameter,&para_desc))
			{
				//handleParameter(&para_desc);
			}
		} // for(TInt i = 0 ; i < desc.Parameters; i ++)
		D3DXHANDLE hFunction;
		D3DXFUNCTION_DESC func_desc;
		pEffect->GetFunctionDesc(vNull,&func_desc);
		for(TInt i = 0 ; i < desc.Functions; i ++) 
		{
			hFunction = pEffect->GetFunction(i);
			if(hFunction == vNull)continue;
			if(XE_OK == pEffect->GetFunctionDesc(hFunction,&func_desc))
			{
				xInfor1A("%s",func_desc.Name);
				for(TInt k = 0; k < tech_desc.Passes ; k ++)
				{
					hAnnotation = pEffect->GetAnnotation(hFunction,k);
					if(hAnnotation == vNull)continue;
					if(XE_OK == pEffect->GetString(hAnnotation,&strValue))
					{
						xInfor1A("%s",strValue);
					}
				}
			}
		} // for(TInt i = 0 ; i < desc.Functions; i ++)
		return vTrue;
	}
	
}